﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;

namespace BLL
{
  public class ConfigBLL
  {
    public bool isHasValue()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        if (data.Configs.ToList().Count > 0) return true;
        else return false;
      }
    }

    public Config GetDefautl()
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        return data.Configs.FirstOrDefault();
      }
    }
    public void UpdateContact(string strContact,string strContact_En)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        if (!isHasValue())
        {
          Config obj = new Config();
          obj.Id = 1;
          obj.Contact = strContact;
          obj.Contact_En = strContact_En;

          data.Configs.InsertOnSubmit(obj);
        }
        else
        {
          Config obj = data.Configs.FirstOrDefault();
          obj.Contact = strContact;
          obj.Contact_En = strContact_En;
        }

        data.SubmitChanges();
      }
    }

    public void UpdateFooter(string strFooter, string strFooter_En)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))
      {
        if (!isHasValue())
        {
          Config obj = new Config();
          obj.Id = 1;
          obj.Footer = strFooter;
          obj.Footer_En = strFooter_En;
          data.Configs.InsertOnSubmit(obj);
        }
        else
        {
          Config obj = data.Configs.FirstOrDefault();
          obj.Footer = strFooter;
          obj.Footer_En = strFooter_En;
        }

        data.SubmitChanges();
      }
    }

    public void UpdateSEO(string description, string keyword, string copyright, string author)
    {
      using (var data = new DigitalColorCMSDataContext(_Global.StringConnect))      
      {
        if (!isHasValue())
        {
          Config obj = new Config();
          obj.Id = 1;
          obj.Description = description;
          obj.Keywords = keyword;
          obj.Copyright = copyright;
          obj.Author = author;
        }
        else 
        {
          Config obj = data.Configs.FirstOrDefault();
          obj.Description = description;
          obj.Keywords = keyword;
          obj.Copyright = copyright;
          obj.Author = author;
        }
        data.SubmitChanges();
      }
    }
  }
}
